/*
 * @Date: 2022-09-07 11:44:49
 * @FilaName: 路由配置
 * @LastEditTime: 2022-09-14 17:33:35
 * @FilePath: /llb-h5/src/router/index.ts
 */
import { createRouter, createWebHistory } from "vue-router"
const getRoutes = () => {
  // 简单格式化
  const files = import.meta.glob("../pages/**/index.vue");
  const routes = Object.entries(files).map(([file, module]) => {
    const path = file.match(/pages(\S*)\/index\.vue/)?.[1]
    return {
      path: `${path}`,
      name: path,
      meta: {
        title: path,
      },
      component: module
    }
  })
  routes.push()
  return routes
}

// 创建路由配置
const router = createRouter({
  history: createWebHistory(),
  routes: [...getRoutes(),
    {
      path: '/:pathMatch(.*)',
      redirect: '/404',
      name: 'NotFound',
    }
  ]
})
export default router

